from pyecharts.charts import Map
from pyecharts import options as opts
import pandas as pd

data = pd.read_csv('csv/DXYArea.csv', usecols=['countryEnglishName', 'provinceName', 'province_zipCode', 'province_confirmedCount'])
data = data.head(294)
attr = ['China', 'Greenland']
value = [83021, 13]
for i in range(0, 294):
    if data.values[i][2] != 0 and data.values[i][0] not in attr:
        attr.append(data.values[i][0])
        value.append(data.values[i][3])

print(attr, value)
# value = [95.1, 23.2, 43.3, 66.4, 88.5]
# attr = ["China", "Canada", "Brazil", "Russia", "United States"]
sequence = list(zip(attr, value))


def map_visualmap(sequence, name) -> Map:
    c = (
        Map()
            .add('', sequence, "world", is_map_symbol_show=False)
            .set_series_opts(label_opts=opts.LabelOpts(is_show=False))
            .set_global_opts(
            title_opts=opts.TitleOpts(title=name, pos_left='40%', title_textstyle_opts=(
                opts.TextStyleOpts(color='black', font_size=15))),
            visualmap_opts=opts.VisualMapOpts(
                  is_piecewise=True,  # 设置是否为分段显示
                  # 自定义的每一段的范围，以及每一段的文字，以及每一段的特别的样式。例如：
                  pieces=[
                      {"min": 500000, "label": '>500000人', "color": "#FF3030"},
                      # 不指定 max，表示 max 为无限大（Infinity）。
                      {"min": 100000, "max": 500000, "label": '100000-500000人',
                       "color": "#FF4500"},
                      {"min": 50000, "max": 100000, "label": '50000-100000人', "color": "#FF7F50"},
                      {"min": 10000, "max": 50000, "label": '10000-50000人', "color": "#FFA500"},
                      {"min": 1, "max": 10000, "label": '1-10000人', "color": "#FFDEAD"},
                      # {"value": 0.004, "label": '123（自定义特殊颜色）', "color": 'grey'},# //表示 value 等于 123 的情况
                      # {"max": 0, "color": "blue"}     # 不指定 min，表示 min 为无限大（-Infinity）。
              ]
                                              )
        )
    )
    return c


map = map_visualmap(sequence, "6月2日全球确诊人数")
map.render(path='./test.html')
